<?php
function getConferences() {
	global $confString, $dbname, $db, $db_selected;
	
	$sql = "SELECT * from transConferences ORDER BY DateEnd DESC";
	$result = mysql_db_query($dbname,$sql);
	
	$i=0;
	while ($value = mysql_fetch_assoc($result)) {
		if (($i % 2) > 0) { $class = 'noRowClass'; }
			else { $class = "altRow"; }
		
		$cID = $value[CID];
		$dateStart = $value[DateStart];
		$dateEnd   = $value[DateEnd];
		$cTitle    = $value[Title];
		$cDesc     = $value[ConfDescription];
		$cURL      = $value[ConfLink];
		$active    = $value[Active];
		$onHome    = $value[OnHome];
		
		// Is this conference expired?
		$todayString = strtotime(date('Y-m-d'));
		$expired = 0;
		if ( empty($dateEnd) || ($dateEnd == '0000-00-00') ) {
			// We only have a start date
			$dateCompareString   = strtotime($dateStart);
			if ($dateCompareString < $todayString) {
				$expired = 1;			
			}
		} else {
			// We have a start and end date
			$dateCompareString   = strtotime($dateEnd);
			if ($dateCompareString < $todayString) {
				$expired = 1;			
			}
		}
		
		$confString .= '<div class="'.$class.'" id="row'.$cID.'" onMouseOver="rowHoverControls('.$cID.',\'on\');" onMouseOut="rowHoverControls('.$cID.',\'off\',\'noHiLite\')">';
		$confString .= '<div style="padding: 3px; text-align: center; vertical-align: top; width: 50px; float: left;">';
			$confString .= '<div style="display: none;" id="control'.$cID.'">';
			$confString .= '<a href="#" onClick="editEvent('.$cID.'); return false;"><img src="images/buttonEditBig.gif" style="border: none;" alt="Edit" /></a>';
			$confString .= '&nbsp;<a href="#" onClick="confirmDelete(\''.$cID.'\',\'event\'); return false;"><img src="images/buttonDeleteBig.gif" style="border: none;" alt="Delete" /></a>';
			$confString .= '</div>';
		$confString .= '</div><div style="width: 90%; float: left; padding: 3px;">';
		
		$confString .= '<p><b>';
		if ($expired == 1) {
			$confString .= '<span style="color: red; font-weight: bold;">[Expired]</span> ';
		}
		
		$confString .= $cTitle.'</b></p>';
		
		// Check for onHome
		$confString .= '<div id="onHomeDiv'.$cID.'" style="margin-left: 5px;">';
		if ($onHome == 1) {
			$confString .= '<img src="images/iconCheckGreenOn.gif" onClick="swapOnHome('.$cID.'); return false;" style="cursor: pointer;" alt="Click to remove from home page" /> On Home Page';
		} else {
			$confString .= '<img src="images/iconCheckGreenOff.gif" onClick="swapOnHome('.$cID.'); return false;" style="cursor: pointer;" alt="Click to display on home page" /> <span style="color: #ccc;">On Home Page</span>';
		}
		$confString .= '</div>';
		
		if (!empty($cDesc)) {
			$confString .= '<p>'.$cDesc.'</p>';
		}
		if (!empty($cURL)) {
			$confString .= '<p><b>Link:</b> <a href="'.$cURL.'" target="_blank" title="Conference Link">'.$cURL.'</a></p>';
		}
		$confString .= '</div><div style="clear: left; height: 10px;"></div></div>';
	
		$i++;
	}
	return $confString;
}

function swapOnHome($cID) {
	global $returnString, $dbname, $db, $db_selected, $pre;
	
	$sql = "SELECT OnHome from transConferences WHERE CID = '$cID'";
	$result = mysql_db_query($dbname,$sql);
	$row = mysql_fetch_assoc($result);
	$onHome = $row[DisplayOnHome];
	
	if ($onHome == 1) {
		$newOnHome = 0;
		$returnString = '<img src="images/iconCheckGreenOff.gif" onClick="swapOnHome('.$cID.'); return false;" style="cursor: pointer;" alt="Click to display on home page" /> <span style="color: #ccc;">On Home Page</span>';	
	} else {
		$newOnHome = 1;
		$returnString = '<img src="images/iconCheckGreenOn.gif" onClick="swapOnHome('.$cID.'); return false;" style="cursor: pointer;" alt="Click to displayu on home page" /> On Home Page';	
	}
	
	$sqlUpdate = "UPDATE ncdb_Events SET DisplayOnHome = '$newOnHome' WHERE EID = '$cID'";
	$result = mysql_db_query($dbname,$sqlUpdate);
	
	return $cID.'|'.$returnString;
}
?>